package com.bw.module_home.home.adapter

import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.bw.module_home.databinding.HomeNoticeItemBinding
import com.bw.module_home.home.model.HomeResult

class HomeNoticeAdapter():RecyclerView.Adapter<HomeNoticeAdapter.HomeNoticeViewHolder>() {
    private val list=mutableListOf<HomeResult>()


    fun setData(data:List<HomeResult>){
        list.clear()
        list.addAll(data)
        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeNoticeViewHolder {
        val binding=HomeNoticeItemBinding.inflate(
            LayoutInflater.from(parent.context),
            parent,
            false
        )

        return HomeNoticeViewHolder(binding)
    }

    override fun getItemCount(): Int {
        Log.d("MYJ", "getItemCount: "+list.size)
       return list.size
    }

    override fun onBindViewHolder(holder: HomeNoticeViewHolder, position: Int) {
        val binding=DataBindingUtil.getBinding<HomeNoticeItemBinding>(holder.itemView) ?:return
        binding.noticeTitle.text=list[position].title
        binding.noticeContent.text=list[position].content
        binding.noticeTime.text=list[position].publishTime
        Log.d("MYJ", "onBindViewHolder: "+list[position].title)

    }

    class HomeNoticeViewHolder(item:HomeNoticeItemBinding):RecyclerView.ViewHolder(item.root)
}

